﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Web;

namespace TSL.Utility
{
    public class jQueryAjaxUtility
    {
        public static string HandlerExtension = ".ashx";
        public static string HandlerPath = "ajax";

        protected static System.Web.UI.Page Page
        {
            get
            {
                return System.Web.HttpContext.Current.Handler as System.Web.UI.Page;
            }
        }


        public static void RegisterClientAjaxScript(Type type)
        {
            if (Page != null)
            {
                RegisterTypeForAjax(type);
            }
        }

        public static void RegisterTypeForAjax(Type t)
        {
            string str = t.FullName + "," + t.Assembly.FullName.Substring(0, t.Assembly.FullName.IndexOf(","));
            string url = "<script type=\"text/javascript\" src=\"" + Page.Request.ApplicationPath + (Page.Request.ApplicationPath.EndsWith("/") ? "" : "/") + HandlerPath + "/" + (((HttpContext.Current.Session != null) && HttpContext.Current.Session.IsCookieless) ? ("(" + HttpContext.Current.Session.SessionID + ")/") : "") + str + HandlerExtension + "\"></script>";
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "AJAX." + t.FullName, url);
        }

        protected string GenertorScript(Type type)
        {
            return string.Empty;
        }
    }
}
